package year2019.month01;

import java.util.HashMap;
import java.util.Map;

/**
 * @desc 描述
 * create on 2019/1/26 by watson
 */
public class MainTest28 {

    public static void main(String[] args){

        Person m = new Person("小明", 12, 300.5);
        Person g = new Person("小刚", 12, 300.5);

        Map<Person, Object> pMap = new HashMap<>();
        pMap.put(m,"优秀学生");
        pMap.put(m,"三好学生");

        pMap.put(g,"三好学生");
        pMap.put(g,"优秀学生");

        Person mUp = new Person("小明", 12, 300.5);
        Person gUp = new Person("小刚", 12, 300.5);

        System.out.println(pMap.get(m));
        System.out.println(pMap.get(mUp));

        System.out.println(pMap.get(g));
        System.out.println(pMap.get(gUp));

    }

}


class Person{

    String name;
    int age;
    double money;

    public Person(String name, int age, double money){
        this.name = name;
        this.age = age;
        this.money = money;
    }

    @Override
    public boolean equals(Object o){
        if (o==this){
            return true;
        } else if (!(o instanceof Person)){
            return false;
        } else {
            Person other = (Person) o;
            if (other.name.equals(this.name) && other.age==this.age && other.money==this.money){
                return true;
            }
            return false;
        }
    }

    @Override
    public int hashCode(){
        int result = 19;

        Object name = this.name;
        result = result * 19 + (name==null? 29 : name.hashCode());

        result = result * 19 + age;

        result = result * 19 + (int)(Double.doubleToLongBits(money) ^ Double.doubleToLongBits(money)>>32);

        return result;
    }

}

